import { HttpClient, HttpClientProxy, Interceptor } from './HttpClient';

export class Base {
  private readonly httpClient: HttpClient;

  constructor(baseUrl: string) {
    this.httpClient = new HttpClient(baseUrl);
  }

  setDefaultHeaders(headers: Record<string, string>) {
    this.httpClient.setDefaultHeaders(headers);
  }

  addHeaders(headers: Record<string, string>) {
    this.httpClient.addHeaders(headers);
  }

  setHttpClientProxy(httpClientProxy: HttpClientProxy) {
    this.httpClient.setHttpClientProxy(httpClientProxy);
  }

  getHttpClient() {
    return this.httpClient;
  }

  // 添加拦截器
  addInterceptor(interceptor: Interceptor, type: 'request' | 'response' = 'request') {
    this.httpClient.addInterceptor(interceptor, type);
  }

  post(endpoint: string, body: any, headers?: Record<string, string>) {
    return this.httpClient.post(endpoint, body, headers);
  }

  put(endpoint: string, body: any, headers?: Record<string, string>) {
    return this.httpClient.put(endpoint, body, headers);
  }

  delete(endpoint: string, body?: any, headers?: Record<string, string>) {
    return this.httpClient.delete(endpoint, body, headers);
  }

  get(endpoint: string, params?: Record<string, any>, headers?: Record<string, string>) {
    return this.httpClient.get(endpoint, params, headers);
  }
}